<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>警告资源管理</title>
	<meta name="decorator" content="default"/>
	<script type="text/javascript">
		var imgflag=true;
		$(document).ready(function() {
			//$("#name").focus();
			$("#inputForm").validate({
				submitHandler: function(form){
					
					
					 var table = document.getElementById("eleSourceAlarmList");
	                    var rows = table.rows.length ;
	                    if(rows!=0){
                            $("#eleSourceAlarmList tr").each(function(){
                                imgflag=true;
                                var reg = /\d+/g;
                                var str = this.id;
                                var i = str.match(reg)
                                var image = $("#image_"+i).val();
                                var imageCn = $("#imageCn_"+i).val();
                                if(document.getElementById("eleSourceAlarmList"+i).className!="error") {
                                    if ((image == null || image == "") && (imageCn == null || imageCn == "")) {
                                        alertx("<spring:message code='tip.chooseimg'/>");
                                        imgflag = false;
                                        return false;
                                    }
                                }
							})}
							if(imgflag){
                                loading('<spring:message code="common.subbmiting"/>');
                                timeVali($("#btnSubmit"));
                                form.submit();
							}


				},
				errorContainer: "#messageBox",
				errorPlacement: function(error, element) {
					$("#messageBox").text("输入有误，请先更正。");
					if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
						error.appendTo(element.parent().parent());
					} else {
						error.insertAfter(element);
					}
				}
			});
		});
		function addRow(list, idx, tpl, row){
			$(list).append(Mustache.render(tpl, {
				idx: idx, delBtn: true, row: row
			}));
			$(list+idx).find("select").each(function(){
				$(this).val($(this).attr("data-value"));
			});
			$(list+idx).find("input[type='checkbox'], input[type='radio']").each(function(){
				var ss = $(this).attr("data-value").split(',');
				for (var i=0; i<ss.length; i++){
					if($(this).val() == ss[i]){
						$(this).attr("checked","checked");
					}
				}
			});
		}
		function delRow(obj, prefix){
			var id = $(prefix+"_id");
			var delFlag = $(prefix+"_delFlag");
			if (id.val() == ""){
				$(obj).parent().parent().remove();
			}else if(delFlag.val() == "0"){
				delFlag.val("1");
				$(obj).html("&divide;").attr("title", "撤销删除");
				$(obj).parent().parent().addClass("error");
                $(obj).parent().parent().css("display","none");
			}else if(delFlag.val() == "1"){
				delFlag.val("0");
				$(obj).html("&times;").attr("title", "<spring:message code='common.delete'/>");
				$(obj).parent().parent().removeClass("error");
			}
		}
	</script>
</head>
<body>
	<ul class="nav nav-tabs">
		<li><a href="${ctx}/source/alarm/eleSourceAlarmGroup/"><spring:message code="alarm.list"/></a></li>
		<li class="active"><a href="${ctx}/source/alarm/eleSourceAlarmGroup/form?id=${eleSourceAlarmGroup.id}">
			<shiro:hasPermission name="source:alarm:eleSourceAlarmGroup:edit">
				<c:if test="${not empty eleSourceAlarmGroup.id}">
					<spring:message code="source.alarm.modify"/>
				</c:if>
				<c:if test="${empty eleSourceAlarmGroup.id}">
					<spring:message code="source.alarm.add"/>
				</c:if>
		</shiro:hasPermission>
			<shiro:lacksPermission name="source:alarm:eleSourceAlarmGroup:edit">
				<spring:message code="source.alarm.info"/>
			</shiro:lacksPermission>
		</a>
		</li>
	</ul><br/>
	<form:form id="inputForm" modelAttribute="eleSourceAlarmGroup" action="${ctx}/source/alarm/eleSourceAlarmGroup/save" method="post" class="form-horizontal">
		<form:hidden path="id"/>
		<sys:message content="${message}"/>
		<div class="control-group">
			<label class="control-label"><spring:message code="common.dname"/>：</label>
			<div class="controls">
				<form:input path="name" htmlEscape="false" maxlength="25" class="input-large required"/>
												<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label"><spring:message code="alarm.default.audio"/>：</label>
			<div class="controls">
				<form:hidden id="defaudio" path="defaudio" htmlEscape="false" maxlength="255" class="input-large"/>
				<sys:ckfinder input="defaudio" type="audios" uploadPath="/source/alarm" selectMultiple="false" langCode="${langCode}"/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label"><spring:message code='common.remarks'/>：</label>
			<div class="controls">
				<form:textarea path="remarks" htmlEscape="false" rows="2" maxlength="255" class="input-xlarge "/>
			</div>
		</div>
			<div class="control-group">
				<label class="control-label"><spring:message code="alarm.items"/>：</label>
				<div class="controls">
					<table id="contentTable" class="table table-striped table-bordered table-condensed" style="">
						<thead>
							<tr>
								<th class="hide"></th>
								<th><spring:message code="alarm.type"/></th>
								<th><spring:message code="alarm.voice"/></th>
								<th><spring:message code="alarm.picture.path"/></th>
								<th><spring:message code="alarm.picture.cn.path"/></th>								
								<%--<th><spring:message code='common.remarks'/></th>--%>
								<shiro:hasPermission name="source:alarm:eleSourceAlarmGroup:edit"><th width="10">&nbsp;</th></shiro:hasPermission>
							</tr>
						</thead>
						<tbody id="eleSourceAlarmList">
						</tbody>
						<shiro:hasPermission name="source:alarm:eleSourceAlarmGroup:edit"><tfoot>
							<tr style="background-color:#fdfdfd;"><td colspan="6"><a href="javascript:" onclick="addRow('#eleSourceAlarmList', eleSourceAlarmRowIdx, eleSourceAlarmTpl);eleSourceAlarmRowIdx = eleSourceAlarmRowIdx + 1;" class="btn"><spring:message code="common.add"/></a></td></tr>
						</tfoot></shiro:hasPermission>
					</table>
					<script type="text/template" id="eleSourceAlarmTpl">//<!--
						<tr id="eleSourceAlarmList{{idx}}">
							<td class="hide">
								<input id="eleSourceAlarmList{{idx}}_id" name="eleSourceAlarmList[{{idx}}].id" type="hidden" value="{{row.id}}"/>
								<input id="eleSourceAlarmList{{idx}}_delFlag" name="eleSourceAlarmList[{{idx}}].delFlag" type="hidden" value="0"/>
							</td>
							<td>
								<input id="eleSourceAlarmList{{idx}}_type" name="eleSourceAlarmList[{{idx}}].type" value="{{row.type}}" class="input-small required" />
									
							</td>
							<td>
								<input type="hidden" name="eleSourceAlarmList[{{idx}}].volume" type="text" value="{{row.volume}}" id="volume_{{idx}}" value="{{row.volume}}" maxlength="255" class="input-small"/>
								<sys:ckfinder input="volume_{{idx}}" type="audios" uploadPath="/source/alarm" selectMultiple="false"/>
							</td>
							<td>
								<input type="hidden" name="eleSourceAlarmList[{{idx}}].image" type="text" value="{{row.image}}" id="image_{{idx}}" maxlength="255" class="input-small "/>
								<sys:ckfinder input="image_{{idx}}" type="images" uploadPath="/source/alarm" selectMultiple="false"/>
							</td>
							<td>
								<input type="hidden" name="eleSourceAlarmList[{{idx}}].imageCn" type="text" value="{{row.imageCn}}" id="imageCn_{{idx}}" maxlength="255" class="input-small "/>
								<sys:ckfinder input="imageCn_{{idx}}" type="images" uploadPath="/source/alarm" selectMultiple="false"/>
							</td>
							<%--<td>
								<textarea id="eleSourceAlarmList{{idx}}_remarks" name="eleSourceAlarmList[{{idx}}].remarks" rows="1" maxlength="255" class="input-small ">{{row.remarks}}</textarea>
							</td>--%>
							<shiro:hasPermission name="source:alarm:eleSourceAlarmGroup:edit"><td class="text-center" width="10">
								{{#delBtn}}<span class="close" onclick="delRow(this, '#eleSourceAlarmList{{idx}}')" title="<spring:message code='common.delete'/>">&times;</span>{{/delBtn}}
							</td></shiro:hasPermission>
						</tr>//-->
					</script>
					<script type="text/javascript">
						var eleSourceAlarmRowIdx = 0, eleSourceAlarmTpl = $("#eleSourceAlarmTpl").html().replace(/(\/\/\<!\-\-)|(\/\/\-\->)/g,"");
						$(document).ready(function() {
							var data = ${fns:toJson(eleSourceAlarmGroup.eleSourceAlarmList)};
							for (var i=0; i<data.length; i++){
								addRow('#eleSourceAlarmList', eleSourceAlarmRowIdx, eleSourceAlarmTpl, data[i]);
								eleSourceAlarmRowIdx = eleSourceAlarmRowIdx + 1;
							}
						});
					</script>
				</div>
			</div>
		<div class="form-actions">
			<shiro:hasPermission name="source:alarm:eleSourceAlarmGroup:edit"><input id="btnSubmit" class="btn btn-primary" type="submit" value="<spring:message code='common.save'/>"/>&nbsp;</shiro:hasPermission>
			<input id="btnCancel" class="btn" type="button" value="<spring:message code='common.back'/>" onclick="history.go(-1)"/>
		</div>
	</form:form>
</body>
</html>